// File:       piscmd07.c++
// Version:    1.00
// Author:     (c) Miles Sabin, 1997
// Purpose:    ignore command

// Change log:
//  27/03/97   v. 1.00

#include "piscmds.h"

#include "istream.h"
#include "streambuf.h"


// Implementation of IgnoreCommand

IgnoreCommand::IgnoreCommand(basic_istream_char& is, streamsize n, int delim)
  : n_(n),
    delim_(delim),
    gcount_(0)
  { execute_template(is, true); }

IgnoreCommand::~IgnoreCommand()
  {}

ios::iostate IgnoreCommand::execute(basic_istream_char& is)
  {
    ios::iostate state = ios::goodbit;

    basic_streambuf_char* sb = is.rdbuf();

    int c = 0;
    while(n_ > 0 && (c = sb->snextc()) != basic_istream_char::traits::eof() && c != delim_)
    {
      ++gcount_;
      --n_;
    }

    return (c == basic_istream_char::traits::eof() ? ios::eofbit : ios::goodbit);
  }


// Implementation of basic_istream_char

basic_istream_char& basic_istream_char::ignore(streamsize n, int delim)
  {
    gcount_ = 0;

    IgnoreCommand cmd(*this, n, delim);
    gcount_ = cmd.gcount();

    return *this;
  }

